@import "../base/colors.less";
@import "../utils/flex";
@import "../utils/decorators.less";

.btn {
  display: inline-block;
  height: 30px;
  padding: 0 10px;
  border: 1px solid #ddd;
  background: #fafafa;
  border-radius: 2px;
  color: @color-text;
  font-size: 13px;
  line-height: 26px;
  letter-spacing: .25px;
  font-weight: 400;
  cursor: pointer !important;

  &.small {
    height: 24px;
    line-height: 20px;

    * {
      vertical-align: top;
      line-height: 20px;
    }
  }

  &.plain {
    background: none;
    border: none;
    color: @color-text--muted;
    line-height: 28px;

    &:not(.toggleable) {
      padding: 0 3px;
    }

    &:hover {
      color: @color-text;
      background: none;
    }

    &.accent:hover {
      color: @blue;
    }

    &:focus {
      box-shadow: none;
    }
  }

  i {
    line-height: 100%;
    line-height: 30px;
    vertical-align: middle;

    &.fa-plus {
      font-size: 10.5px;
      margin-top: -3px;
    }

    &:last-child {
      margin-left: 2px;
      margin-right: 0;
    }

    &:first-child {
      margin-left: 0;
      margin-right: 2px;
    }

    &:first-child:last-child {
      margin-left: 0;
      margin-right: 0;
    }
  }

  * {
    cursor: pointer;
    display: inline-block;
  }

  &:focus {
    outline: none;
    box-shadow: 0 0 0 2px fadeout(@color-link, 50%);
  }

  &.full-width {
    width: 100%;
  }

  &.center {
    text-align: center;
  }

  &.thick {
    font-size: 14px;
    font-weight: normal;
    height: 35px;
    padding: 0 12px;
  }

  &.pressed {
    box-shadow: inset 0px 0 5px rgba(0,0,0,0.1);
    background: linear-gradient(to top, #ddd, #ccc);

    &:hover {
      box-shadow: inset 0px 0 2px rgba(0,0,0,0.1);
      background: linear-gradient(to top, #ddd, #ccc);
      cursor: default;
    }
  }

  &:hover {
    text-decoration: none;
    background: #eee;
  }

  &[disabled="disabled"],
  &.disabled,
  &:disabled {
    &:extend(.btn.nofocus);
    cursor: default;
    background: #fafafa !important;
    color: rgba(0,0,0,.4) !important;
    border: 1px solid #eee !important;
    font-weight: 400 !important;
    -webkit-font-smoothing: initial !important;

    .spinner {
      color: #aaa !important;
    }

    &:hover {
      cursor: default;
      background: #fafafa;
    }
  }

  .spinner {
    display: inline-block;
    position: relative;
    top: 1px;
    color: inherit;
  }
}

.btn.warning {
  color: #fff;
  background: shade(@red, 20%);
  border-color: shade(@red, 20%);

  &.pressed,
  &:hover {
    background: shade(@red, 23%);
    border-color: shade(@red, 23%);
  }
}

.btn.success {
  background: @background-button--success;
  color: @color-button--success;
  border-color: @background-button--success;

  &.pressed,
  &:hover {
    background: shade(@background-button--success, 9%);
    border-color: shade(@background-button--success, 9%);
  }
}

.btn.transparent {
  border-color: transparent;
  background: none;
  font-weight: 400;

  &:hover {
    background: rgba(0,0,0,.075);
    color: darken(@color-button, 10%);
  }
}

.btn.primary {
  background: @blue;
  color: #fff;
  border: 1px solid @blue;
  transition: background .1s ease;

  &.pressed {
    box-shadow: inset 0px 0 5px rgba(0,0,0,0.25)
  }

  &:hover {
    background: shade(@blue, 13%);
  }
}

&.lime {
  background: shade(@lime, 5%);
  color: shade(@lime, 55%);
  border: 1px solid shade(@lime, 5%);

  &:hover {
    background: shade(@lime, 12%);
    border: 1px solid shade(@lime, 12%);
  }
}

.btn.btn-split-group {
  height: auto;
  padding: 0;

  .btn-split-section {
    height: 28px;
    padding: 0 10px;
    border-right: 1px solid #ddd;

    &:last-child {
      border-right: 0;
    }
  }
}

.btn-group {
  display: inline-flex;

  .btn {
    margin: 0 !important;
    border-radius: 0;
    border-right-width: 0;
  }

  & > :first-child {
    border-top-left-radius: 2px;
    border-bottom-left-radius: 2px;
    margin-right: 0;
  }

  & > :last-child {
    border-top-right-radius: 2px;
    border-bottom-right-radius: 2px;
    border-right-width: 1px;
    margin-left: 0;
  }
}

.dropdown-btn-container {
  display: inline-block;
  position: relative;

  &.open .dropdown-btn-list {
    display: block;
  }

  &.open .toggleable.btn {
    background: shade(@background-menu, 10%);
    box-shadow: inset 0px 1px 0px rgba(0, 0, 0, 0.07);
  }
}

.dropdown-btn-list {
  display: none;
  position: absolute;
  z-index: 1;
  top: 24px;
  right: 0;
  background: #fff;
  border: 1px solid @border-menu;
  width: 149px;
  box-shadow: 2px 2px 5px rgba(0,0,0,0.1);
  border-radius: 2px;
  padding: 2px 0;

  * {
    cursor: pointer;
  }
  hr {
    margin: 2px 0;
  }

  // TODO this should just be .dropdown-item -tbv
  .dropdown-item, & > div, & > a {
    width: 100%;
    display: block;
    padding: 7px 7px;
    color: @color-text;

    i {
      width: 15px;
      display: inline-block;
      text-align: center;
    }

    &.disabled {
      color: @color-text--light;
    }

    &:hover {
      text-decoration: none;
    }

    &:hover:not(.disabled) {
      background: @blue;
      color: #fff;
    }
  }

  & > div, .dropdown-item {
    padding: 8px 15px;
    border-bottom: 1px solid @border-menu;

    &:last-child {
      border: 0;
    }

    .title {
      font-weight: 600;
      margin-bottom: 5px;

      i {
        margin-right: 2px;
      }
    }

    &:hover .desc {
      color: #fff;
    }
  }
}

.btn-bar {
  &:extend(.flex);

  .btn {
    border-radius: 0 !important;

    &:first-child {
      border-radius: 2px 0 0 2px !important;
    }

    &:last-child {
      border-radius: 0 2px 2px 0 !important;
    }

    &:not(:first-child) {
      border-left: 0;
    }
  }
}

a.btn span {
  vertical-align: baseline;
}

.btn,
button {

  &.nofocus:focus {
    outline: 0;
    box-shadow: none;
  }
}